package com.bsj.power.system.web;

import com.bsj.power.common.file.log.OperateLogRead;
import com.bsj.power.common.file.log.OperateLogSaveQueue;
import com.bsj.power.common.file.log.OperateLogWriteAndRead;
import com.bsj.power.common.util.SpringUtil;
//import com.bsj.power.system.config.monitor.ServerMonitor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * @author yinhao
 * @version 1.0
 * @description 初始化
 * @date 2024/6/3
 */
@Component
@Slf4j
@Import(SpringUtil.class)
public class Action implements CommandLineRunner {

    @Autowired
    private OperateLogWriteAndRead operateLogWriteAndRead;

    @Autowired
    private OperateLogRead operateLogRead;

//    @Autowired
//    private ServerMonitor serverMonitor;

    /**
     * 初始化车辆信息
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        //文件存储
        OperateLogSaveQueue.start("operateLog");
        operateLogWriteAndRead.start("operateLog");
        operateLogRead.start("operateLog");
        // 监控告警
//        serverMonitor.startAlertMonitor();
    }

    /**
     * 销毁使用的方法
     */
    @PreDestroy
    public void destroy() throws Exception {
        OperateLogSaveQueue.stop();
        operateLogWriteAndRead.stop();
        log.info("结束关闭");
    }
}
